package com.fuyun.microservice.handler;

import com.fuyun.microservice.codec.PacketType;
import com.fuyun.microservice.codec.msg.Message;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ChannelHandler.Sharable
public class HeartbeatMessageHandler extends AuthAbstractHandler<Message> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        channelAuth(ctx,msg);

        if(msg.getHeader().getCommandId()== PacketType.HEARTBEARTREQUEST.getCommandId()){
            log.debug("heartbeat from {}",ctx.channel());
            ctx.fireChannelReadComplete();
        }

        ctx.fireChannelRead(msg);
    }
}
